snippet gtk_basic_template "Description" b
#include <gtk/gtk.h>

void destroy(GtkWidget *widget, gpointer data)
{
    //  If don't call this callback, program will not quit outright.
    gtk_main_quit();
}

int main(int argc, char *argv[])
{
    gtk_init(&argc, &argv);

    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "My first program helloworld!");
    gtk_container_set_border_width(GTK_CONTAINER(window), 150);

    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);

    GtkWidget *button = gtk_button_new_with_label("Hello World");

    gtk_container_add(GTK_CONTAINER(window), button);

    gtk_widget_show_all(window);

    gtk_main();
    return 0;
}
endsnippet

snippet gtk_glade_builder "use glade to generate UI" b
// gcc -o main main.c \`pkg-config --cflags --libs gtk+-3.0\` -export-dynamic
gtk_init(&argc, &argv);

GtkBuilder *builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "glade_test.glade", NULL);

GtkWidget *window = GTK_WIDGET(gtk_builder_get_object(builder, "window_main"));
gtk_builder_connect_signals(builder, NULL);

gtk_widget_show(window);
g_object_unref(builder);

gtk_main();
endsnippet

snippet glib_main_loop "glib main loop template" b
// gcc test.c \`pkg-config --cflags --libs glib-2.0\`
GMainContext* ${1:context} = g_main_context_new();
GMainLoop* ${2:loop} = g_main_loop_new($1, FALSE);
GSource* ${3:source} = NULL;

$3 = g_timeout_source_new_seconds(1);
g_source_set_callback($3, ${4:callback}, $2, NULL);
g_source_attach($3, $1);

g_main_loop_run($2);
endsnippet

snippet glib_unit_test "glib unit test" b
g_test_init(&argc, &argv, NULL);
g_test_add_func("/package_name/unit", computationTest);
return g_test_run();
endsnippet

